﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DataAccess;
using Entity;

namespace Controller
{
     public class CompanyController:ControllerBase
    {
        public CompanyEntity FindCompany()
        {
            Company company = (from c in Sdc.Companies
                               select c).SingleOrDefault();
            CompanyEntity companyEntity = TransformCompanyToCompanyEntity(company);
            return companyEntity;
        }

        public int UpdateCompany(CompanyEntity companyEntity)
        {
            Company company = (from c in Sdc.Companies
                               select c).SingleOrDefault();
            company.Name = companyEntity.CompanyName;
            company.Address = companyEntity.Address;
            company.Postal = companyEntity.ZipCode;
            company.Telephone = companyEntity.Phone;
            company.Fax = companyEntity.Fax;
            company.ContactPerson = companyEntity.ContactPerson;
            Sdc.SubmitChanges();
            return 0;
        }

         public static CompanyEntity TransformCompanyToCompanyEntity(Company company)
         {
             CompanyEntity companyEntity=new CompanyEntity();
             companyEntity.CompanyName = company.Name;
             companyEntity.Address = company.Address;
             companyEntity.ZipCode = company.Postal;
             companyEntity.Phone = company.Telephone;
             companyEntity.Fax = company.Fax;
             companyEntity.ContactPerson = company.ContactPerson;
             return companyEntity;
         }
    }
}
